﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace ConjureBivouac2012.GameStates
{
    public class GameCredits : IGlobalGameState
    {
        private Texture2D _background;

        private bool EnterHit = false;
        private ContentManager _contentManager = null;
        private GraphicsDevice _device;
        private GamePadState _previousGamePadState;
        private KeyboardState _previousKeyboardState;

        public GameCredits(ContentManager contentManager, GraphicsDevice device)
        {
            _contentManager = contentManager;
            _device = device;
            _previousGamePadState = GamePad.GetState(PlayerIndex.One);
            _previousKeyboardState = Keyboard.GetState();

            _background = contentManager.Load<Texture2D>("CreditsScreen");
        }

        public void Enter()
        {
            EnterHit = false;

            //Initialize credits screen

        }

        public void Execute(GameTime gameTime)
        {
            if (EnterHit)
            {
                Program.GetGameInstance.SetState(new MainMenu(_contentManager, _device));
            }
            else
            {
                GamePadState gamePad = GamePad.GetState(PlayerIndex.One);
                KeyboardState keyboard = Keyboard.GetState();

                if ((keyboard.IsKeyDown(Keys.Enter) && !_previousKeyboardState.IsKeyDown(Keys.Enter)) || (gamePad.Buttons.Start == ButtonState.Pressed && _previousGamePadState.Buttons.Start == ButtonState.Released) ||
                    (gamePad.Buttons.A == ButtonState.Pressed && _previousGamePadState.Buttons.A == ButtonState.Released))
                {
                    EnterHit = true;
                }
            }

            _previousGamePadState = GamePad.GetState(PlayerIndex.One);
            _previousKeyboardState = Keyboard.GetState();
        }

        public void Exit()
        {

        }

        public void Draw(SpriteBatch theSpriteBatch)
        {
            theSpriteBatch.Draw(_background, new Rectangle(0, 0, _device.Viewport.Width, _device.Viewport.Height), null, Color.White, 0, new Vector2(0, 0),
                                        SpriteEffects.None, 1);
        }
    }
}
